﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using socialnexus.classes.models;
using socialnexus.classes.pages;

namespace socialnexus.admin.EntryPoints.Users
{
    public partial class Add : ProtectedPage
    {
        socialnexus.classes.models.EntryPoint ep;

        protected void Page_Load(object sender, EventArgs e)
        {
            ep = socialnexus.classes.models.EntryPoint.GetById(Request.QueryString["EntryPointId"].ToString());
            lblEntryPoint.Text = ep.Name;

            hlBack.NavigateUrl = "Default.aspx?EntryPointId=" + ep.EntryPointId.ToString();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string conditions = "";
            if (ep.getUsers().Rows.Count > 0)
            {
                conditions = "SiteUserId NOT IN (" + String.Join(",", ep.getUserIds().ToArray()) + ") ";
            }
            
            rptrUsers.DataSource = SiteUser.Search(txtUserName.Text, conditions);
            rptrUsers.DataBind();
        }

        protected void lbDoAdd_Click(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            HiddenField hf = (HiddenField)lb.Parent.FindControl("hfUserId");

            ep.addUser(hf.Value);
            Response.Redirect("~/admin/EntryPoints/Users/Default.aspx?EntryPointId=" + 
                ep.EntryPointId.ToString());
            Response.Close();
        }
    }
}
